package com.seventeen.mq.proxy.core.service.impl;

import com.seventeen.mq.proxy.common.constant.DelFlagConstants;
import com.seventeen.mq.proxy.common.exception.base.BaseException;
import com.seventeen.mq.proxy.core.domain.MqConsumerProxy;
import com.seventeen.mq.proxy.core.mapper.MqConsumerProxyMapper;
import com.seventeen.mq.proxy.core.service.IMqConsumerProxyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 消息消费代理 服务层处理
 *
 * @author seventeen
 */
@Service
public class MqConsumerProxyServiceImpl implements IMqConsumerProxyService {
    @Autowired
    private MqConsumerProxyMapper mqConsumerProxyMapper;

    @Override
    public List<MqConsumerProxy> list() {
        return mqConsumerProxyMapper.list();
    }

    @Override
    public List<MqConsumerProxy> queryList(MqConsumerProxy mqConsumerProxy) {
        return mqConsumerProxyMapper.selectList(mqConsumerProxy);
    }

    @Override
    public void add(MqConsumerProxy mqConsumerProxy) {
        if (mqConsumerProxyMapper.getByConsumerProxyGroup(mqConsumerProxy.getConsumerProxyGroup()) != null) {
            throw new BaseException("消费代理组名重复！");
        }
        mqConsumerProxy.setVersion(Long.toString(System.currentTimeMillis()));
        mqConsumerProxy.setDelFlag(DelFlagConstants.NORMAL);
        mqConsumerProxyMapper.insert(mqConsumerProxy);
    }

    @Override
    public void update(MqConsumerProxy mqConsumerProxy) {
        mqConsumerProxy.setVersion(Long.toString(System.currentTimeMillis()));
        mqConsumerProxyMapper.update(mqConsumerProxy);
    }
}
